Hello and welcome to the none pay assessment Crist's solution so same as with the pace and basic.
We have 15 questions that cover all topics we need for our sticker.
Case study and.
Yeah if you have the impression that you need some more background on the basics feel free to watch
the next few sessions about the basic none pay coding and follow up questions.
We have the assumption that we already imparted an umpire.
So let's start our quiz
and the key message of the first question is that none pay array only contains one data type and by
converting a list the different data types into a new pay array.
All elements are converted to one data type.
Actually to the lowest common denominator.
And in this case that's the data type string.
So with quotation marks we can transform an integer and will end and float to a string.
So that correct answers string only
here on this question we have an umpire ravers five elements and we have a so-called vector rise or
element y's operation and where we add tend to each element.
So actually we should get the eleven twelve thirteen fourteen fifteen.
So this is correct yeah.
And the key message is that in contrast to lists element y's operations are pretty easy here with an
umpire
so here we have two codes and they are we should determine how many of these codes the return uh the
output.
Six nine twelve 15 18.
And let's have a look at the code one.
So also here we have an element of ICE operation where we first add to and then multiply with three.
So let's start with zero plus two is two times three is six then one plus two is three times three is
nine two plus two is four times three is twelve three plus two is five times three is fifteen and four
plus two is six times three is eighteen.
So code 1 works and let's have a look at CO 2 Here we have the function P arrange and NPR range arranges
integers and the range from six including to 19 excluding and only every third element.
So we are starting with six then we have nine 12 15 and 18 so also Code 2 produces this output here.
So the correct answer is both
so here in this question we have a higher rate with 10 elements and we slicing from the next position
for including to the next position eight excluding and also here the zero based indexing applies.
So we start here with the 0 1 2 3 4.
So our first element of our slices the 5 5 6 7 8 excluding.
So our last element and our slices eight.
So this should be the correct answer.
Here we have some num pi array of us five elements 10 20 30 40 50 and we assign the arrival right a
and then we make a slice of array.
So we take them the first two elements and assign the variable array B so or a B contains of the elements
10 and 20 and then we change the first element of array B and set it to 1 then actually so this answer
is correct the first element of array B is null 1 and actually give us num pay raise then we create
here a slice of array we are not creating a copy.
So Arabia is referencing to the same original object but only to the first two elements and if you change
one of the first two elements of array B we also change the elements of array A's so array a the first
element of array a small one.
And if you want to prevent this behavior of your we have to make a copy of the array a.
So this is a common source for mistakes actually you make a slice and change some element and a slice
of an none pay array and then also the original A changes and we might not even recognize that.
So this is important here
okay.
The question.
Yes.
Which statement is incorrect so incorrect as then that the first element of array is still tense.
Oh no that's correct
here we are creating a one dimensional array with elements from 0 to 7 and then we reshape the one dimensional
array to a two dimensional matrix with four rows and two columns.
So here we have four rows and two columns.
And this is the correct answer.
Here we have a matrix a two dimensional array with a shape 3 5.
So we have three rows and five columns.
And yeah we're we want to index seven.
So here this row is that next position the row and the second row is that index position 1.
So let's move to the column here is column at index position 0 column meeting index position 1 and column
at index position 2.
So row at index position 1 and column and index position 2 should last for 7.
Again we have the same matrix and as this kind of a tricky question so we slice the matrix we take all
rows and the column at an exposition too.
So this this this column here and then we add 100 to each element.
And if you would print this line of code here then you would end up with this answer here but actually
here with this code we are not changing the Matrix itself.
So we are not assigning new values to the column at an exposition tours or actually we haven't changed
the original matrix at all.
And the correct answer is yeah the first one so the matrix my matrix is unchanged.
Here we want to create 20 random integers in the in terms of 1 to 10 both and including and we want
to select all elements that are greater than 5.
And we set up the random C to 1 2 3 to ensure our reproducibility and let's have a look at the answers.
So we want to create 20 random integers in the interval 1 to 10.
So the starting point is including and the ending point and excluding and we need to have 20.
So here this is correct and also this is correct and the second answer is not correct here.
And now the second key message of this question is boolean indexing.
So if you look here at this answer then for each of the 20 random integers we check whether the integer
is greater than 5.
And then we create here an NDA array with twenty billions and print here the end array with Julian's
but actually we do not get here and the India test that's greater than 5 so he and the first answer
we have are we in indexing so we select all elements of our array with 20 integers which are greater
than 5
here we calculate integers to the power of three of us.
List comprehension and num pi code and the key message is that for large numerical operations like in
this case here num pay us fifty two hundred times faster.
So the fastest code should be here in the name pi code with only 1000 calculations and here for code
number 1 and 2 with the same amount of calculation.
So we have 100000 here the unpaid code should be much faster.
So answer 3 to 1 is correct.
Here we have an umpire array from 1 to twenty and we want to create a new array that contains all elements
that fulfils two conditions.
So first of all the element must be divisible by three without remainder.
And the second condition is that the element three and must not be in the array.
So we have two conditions and both must be met.
So we need here and sign.
Here we have an sign your F and or sign in here.
And so this is not the correct answer.
And what we need is really in slicing so this answer is incorrect as it returns only the boolean array
is showing for each element of the array here.
If both conditions are met but the answer does not return the elements itself that fulfill both conditions.
Here we have two conditions.
They are linked with an end and then we are creating as here a bully an array with truth or false for
each element checking of each element.
Fulfills both conditions and then we slice the array only for the elements that fulfill both conditions
so this answer yes correct
here we create 10 random normal distributed numbers.
This mean 50 and standard deviation 10 and we calculate the mean.
Over these 10 numbers.
And we repeat this process 1000 times so we have 1000 simulations.
And in the end we want to return an array with 1000 mean values.
So the question is how many of the following codes are correct.
And until.
Here are three codes are identical so we create 10 times 1000 normal distributed numbers with mean 50
and standard deviation 10.
So we have 10000 the number distributed numbers and code 1.
We reshape these 10000 numbers to 1000 rows and 10 columns and then for each row we take the mean over
the 10 column so x equals 1.
So here we should get a 1000 times the mean of 10 normal distributed numbers.
And here in code to we reshape our 10000 numbers to 10 rows and 1000 columns and then we take the mean
over all 1000 columns so 1000 times over 10 rows.
So also here we should get an array with a 1000 the mean values and code 3 is actually identical to
Kota 2.
First of all we reshape the 10000 numbers into 1000 draws and ten columns and then we transpose the
matrix into 10 rows and 1000 columns and then say mass and co 2 we take the mean for each of the 1000
columns.
So the answer is then that all three codes are correct.
Here we have an array with seven elements from one to seven.
And yeah gets code returns some the output far so we have fear in the middle of the four.
And let's check what answers we have here so we have a person tired of the 19th person.
We have the median and we have the sum so obviously the sum of their array cannot be for the person
time.
There are actually also not really.
And the median is actually here the value where 50 percent of the other elements of the array is um
less or lower than 50 percent is higher.
So the fourth then the medium of our end the array and we can calculate the median with them the number
of function and picked up medium
so here we have a function Y equals cosine x plus except are we want to plot the graph and then Turnbull
minus 10 to 10.
And the question is which code best produces this graph.
So let's have a look at our answers here.
And to plot a graph you need how many data points.
So NPL in space creates us 1000 evenly distributed data points in the interval minus 10 to 10 and MP
range actually only creates 20 data points from minus 10 to 10.
So this is not the optimal answer here.
And comparing answer 2 and 3.
So this in Python standard library no function like cosine.
So we have to calculate the cosine with the number of function and picked up the coast.
And this should be the correct answer here
now our last question.
So we have two dimensional data points that are represented by the ending arrays X for the x coordinate
and y for the y coordinate and we want to fit a linear regression line that best fits the data points.
Yeah the right function for it is the umpire function and P poorly fit where we pass them the arrays
x and y and as we want to have a linear regression line our polynomial degrees should be 1 and not 2.
So here we get a credit rhetoric regression.
So the best answer here is the answer 1.